//统计出现字符最多的次数

exports.tong=(str)=>{
  let  obj=str.split('').reduce((pre,next)=>{
        // console.log(pre,next)
        if(next in pre){
            pre[next]++
        }else{
            pre[next]=1
        }

        return pre
    },{});//{}初始值

    let maxNum=0;
    let maxStr='';

    for (let key in obj) {//遍历对象
        // console.log(obj[key]);
        if(obj[key]>maxNum){
            maxNum=obj[key];//出现最多字符的次数
            maxStr=key;//出现最多的字符
        }
    }
    console.log(maxNum,maxStr)
}

exports.tong2=(str)=>{
    let string=[...str],
    maxvalue='',
    obj={},
    max=0;
    string.forEach((item)=>{
        obj[item]=obj[item]==undefined?1:obj[item]+1;
        if(obj[item]>max){
            max=obj[item]
            maxvalue=item
        }
    })
    console.log(max,maxvalue);
}